<template>
  <view class="content">
    <block v-if="examList.length>0" v-for="(item,index) in examList" :key="index">
      <uni-card :title="item.title" :is-shadow="true" mode="style" :note="getExamTime(item)"
                @click="onExamClick(item)" :thumbnail="getExamImage(item)">
        <view v-if="item.rdm_que_num">题目数：{{ item.rdm_que_num }}</view>
        <view v-if="item.question_list.length>0">题目数：{{ item.question_list.length }}</view>
        <view>答题时间：10分钟</view>
      </uni-card>
    </block>
    <view v-if="examList.length<=0" class="no-data-view" style="color: #777777;">
      <view class="ver-layout-center-all" style="width: fit-content;margin: auto;">
        <image class="no-data-image" src="/static/ic_no_data.jpg"></image>
        <text>暂无考试</text>
      </view>
    </view>
  </view>
</template>

<script>
import {
  paper
} from '../../router.js'
import {convertDateTime} from "@/common/common.js"

export default {
  components: {},
  data() {
    return {
      examList: [],
      convertDateTime
    }
  },
  onLoad() {

  },
  onShow() {
    this.getExamList()
  },
  methods: {
    getExamList() {
      this.$request('exam/exam/getExamPapers', {}).then(res => {
        // debugger
        console.log(res)
        this.examList = res.data
      })
    },
    onExamClick(examItem) {
      uni.navigateTo({
        url: paper + "?paperId=" + examItem._id
      })
    },
    getExamImage(item) {
      return item.image ? item.image : require('@/static/exam_banner.jpg')
    },
    getExamTime(item) {
      let start = convertDateTime(item.sel_time[0])
      let end = convertDateTime(item.sel_time[1])
      return `考试时间：${start} 至 ${end}`
    }
  }
}
</script>

<style>
page {
  background: #fff;
}

.exam-list {
  margin: 10px;
  padding: 15px;
  background: #e8e8e8;
  border-radius: 7px;
  font-size: small;
}

.no-data-view {
  position: fixed;
  top: 35vh;
  width: 100%;
  text-align: center;
}

.no-data-image {
  width: 240px;
  height: 100px;
}
</style>
